﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ThanhTu.GNC.Media.KQXS.DataAccess.BL;

namespace GNCMedia.KQXS.MenuPage
{
    public partial class PageTrucTiep : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Session["StartTime"] = DateTime.Now;
        }

        protected void timmer_countdown_Tick(object sender, EventArgs e)
        {
            DateTime FutureTime1, FutureTime2, FutureTime3;
            TimeSpan RemainingTime1, RemainingTime2, RemainingTime3;

            update_panel_coundownt.Update();
            update_panel_mt.Update();
            UpdatePanel_MN.Update();
            string date = Convert.ToString(DateTime.Today.ToString("yyyy/MM/dd"));
            //18:15:00 PM
            //17:15:00 PM
            //16:45:00 PM
            string everday = date.ToString() + " " + "20:5:00 PM";
            string everdayMT = date.ToString() + " " + "20:5:00 PM";
            string everdayMn = date.ToString() + " " + "20:25:00 PM";

            FutureTime1 = Convert.ToDateTime(everday);
            RemainingTime1 = FutureTime1.Subtract(DateTime.Now);

            FutureTime2 = Convert.ToDateTime(everdayMT);
            RemainingTime2 = FutureTime2.Subtract(DateTime.Now);

            FutureTime3 = Convert.ToDateTime(everdayMn);
            RemainingTime3 = FutureTime3.Subtract(DateTime.Now);
           
           
            string timeMienBac_Hours = "";
            string timeMienBac_Minutes = "";
            string timeMienBac_Seconds = "";

            string timeMienNam_Hours = "";
            string timeMienNam_Minutes = "";
            string timeMienNam_Seconds = "";

            string timeMienTrung_Hours = "";
            string timeMienTrung_Minutes= "";
            string timeMienTrung_Seconds = "";
            #region mb
            if (Convert.ToInt32(RemainingTime1.Hours.ToString()) < 10)
            {
                timeMienBac_Hours = "0"+RemainingTime1.Hours.ToString();
            }else
            {
                timeMienBac_Hours = RemainingTime1.Hours.ToString();
            }

            if (Convert.ToInt32(RemainingTime1.Minutes.ToString()) < 10)
            {
                timeMienBac_Minutes = "0" + RemainingTime1.Minutes.ToString();
            }
            else
            {
                timeMienBac_Minutes = RemainingTime1.Minutes.ToString();
            }

            if (Convert.ToInt32(RemainingTime1.Seconds.ToString()) < 10)
            {
                timeMienBac_Seconds = "0" + RemainingTime1.Seconds.ToString();
            }
            else
            {
                timeMienBac_Seconds = RemainingTime1.Seconds.ToString();
            }
            #endregion
            #region mtrung 
            if (Convert.ToInt32(RemainingTime2.Hours.ToString()) < 10)
            {
                timeMienTrung_Hours = "0" + RemainingTime2.Hours.ToString();
            }
            else
            {
                timeMienTrung_Hours = RemainingTime2.Hours.ToString();
            }

            if (Convert.ToInt32(RemainingTime2.Minutes.ToString()) < 10)
            {
                timeMienTrung_Minutes = "0" + RemainingTime2.Minutes.ToString();
            }
            else
            {
                timeMienTrung_Minutes = RemainingTime2.Minutes.ToString();
            }

            if (Convert.ToInt32(RemainingTime2.Seconds.ToString()) < 10)
            {
                timeMienTrung_Seconds = "0" + RemainingTime2.Seconds.ToString();
            }
            else
            {
                timeMienTrung_Seconds = RemainingTime2.Seconds.ToString();
            }
            #endregion

            if (Convert.ToInt32(RemainingTime3.Hours.ToString()) < 10)
            {
                timeMienNam_Hours = "0" + RemainingTime3.Hours.ToString();
            }
            else
            {
                timeMienNam_Hours = RemainingTime3.Hours.ToString();
            }

            if (Convert.ToInt32(RemainingTime3.Minutes.ToString()) < 10)
            {
                timeMienNam_Minutes = "0" + RemainingTime3.Minutes.ToString();
            }
            else
            {
                timeMienNam_Minutes = RemainingTime3.Minutes.ToString();
            }

            if (Convert.ToInt32(RemainingTime3.Seconds.ToString()) < 10)
            {
                timeMienNam_Seconds = "0" + RemainingTime3.Seconds.ToString();
            }
            else
            {
                timeMienNam_Seconds = RemainingTime3.Seconds.ToString();
            }

            lb_timer.Text = "0"+ RemainingTime1.Days+":"+timeMienBac_Hours+":"+timeMienBac_Minutes+":"+timeMienBac_Seconds;
            lb_time_MT.Text = "0"+RemainingTime2.Days+":"+timeMienTrung_Hours+":"+timeMienTrung_Minutes+":"+timeMienTrung_Seconds;
            lb_time_MN.Text = "0"+RemainingTime3.Days+":"+timeMienNam_Hours+":"+timeMienNam_Minutes+":"+timeMienNam_Seconds;

            //lb_thongbao.Text = "Hiện tại chưa đến giờ quay số mở thưởng. Xổ số Miền Bắc sẽ bắt đầu quay số mở thưởng vào  18h15 hàng ngày";

            lb_thongbao.Text = "Hiện tại chưa đến giờ quay số mở thưởng <br/> Xổ số Miền Bắc sẽ bắt đầu quay số mở thưởng vào 18h15 hàng ngày";

            if (DateTime.Now >= FutureTime1)
            {
                lb_timer.Text = "";
                lb_thongbao.Text = "";
                ResultLotteryBL vResult = new ResultLotteryBL();
                int rowcount = 0;
                Repeate_wait.DataSource = vResult.SelectAll_KQ_User(1, 5, ref rowcount);
                Repeate_wait.DataBind();
                timmer_countdown.Enabled = false;

            }
            if (DateTime.Now >= FutureTime2)
            {
                lb_time_MT.Text = "";
                lb_thongbao.Text = "";
                ResultLotteryBL vResult = new ResultLotteryBL();
                int rowcount = 0;
                Repeater_wait_mt.DataSource = vResult.SelectAll_KQ_User(1, 5, ref rowcount);
                Repeater_wait_mt.DataBind();
                timmer_countdown.Enabled = false;
            }
            if (DateTime.Now >= FutureTime3)
            {
                lb_time_MN.Text = "";
                lb_thongbao.Text = "";
                ResultLotteryBL vResult = new ResultLotteryBL();
                int rowcount = 0;
                Repeater_wait_mn.DataSource = vResult.SelectAll_KQ_User(1, 5, ref rowcount);
                Repeater_wait_mn.DataBind();
                timmer_countdown.Enabled = false;

            }
        }
    }
}